$(() => {
    const token = GetQueryString("token");
    // 获取area_id
    let id = GetQueryString('user_id');
    showMsg();

    //联系
    function showMsg() {
        $.ajax({
            type: "post",
            url: url,
            data: { "method": "Company|user_detail", "token": token, "user_id": id },
            dataType: 'json',
            success: function(res) {
                // console.log(res);
                if (res.status == 1) {
                    let data = res.data;
                    $('.hetitle').html(data.nick_name);
                    $("#img_head").attr("src", data.img_head == '' ? '../img/user.jpg' : data.img_head);
                    $('#nick_name').html(data.nick_name);
                    $("#headImg").attr("src", data.bg_img == '' ? '../img/banner.png' : data.bg_img);
                    $("#read_count").html("浏览量 " + data.read_count);
                    var is_edit = data.is_edit;
                    if (is_edit == 0) {
                        $(".bannerfl").hide();
                    }
                    $("#shdetdt2").html(data.description);
                    var heig = $("#shdetdt2").height();
                    if (heig < 30) {
                        $(".shdetdt3").hide();
                    }
                    $("#main_business").html(data.main_business);
                    $("#phone").html(data.phone);
                    $("#phone").attr('href', 'tel:' + data.phone);
                    $("#address").html(data.area_address + data.address);
                } else if (res.status == 2) {
                    location.href = "fox://logout";
                } else {
                    alert(res.message);
                }
            }
        })
    }

    let page = 1;
    let page_size = 10;
    //次导航切换
    $(".shnav .shnavitem").click(function() {
        $(this).addClass("on").siblings(".shnavitem").removeClass("on");
        var i = $(this).index();
        $(".sh_delsitd .sh_delsit").eq(i).show().siblings(".sh_delsit").hide();
        if (i == 1) {
            page = 1;
            $('.pictureDetails').html('');
            $('.notMore').css('display', 'none');
            ajaxList(page);
        }
    });
    //建材圈
    function ajaxList(page) {
        $.ajax({
            type: "post",
            url: url,
            data: {
                "method": "Company|single_forum",
                "token": token,
                "userid": id,
                'page': page,
                'pagelimit': page_size,
            },
            dataType: 'json',
            success: function(res) {
                // console.log(res);
                if (res.status == 1) {
                    let data = res.data;
                    let html = '';
                    if (data.company_level == 0 || data.user_id == '') {
                        $('.contactService').hide();
                    }
                    data.forEach(item => {
                        let date = getDate(item.create_time);
                        html += `
                            <div class="ringitem">
                                <a href="javascript:;" class="ringtop">
                                    <img src="${item.head_logo == "" ? '../img/user.jpg' : item.head_logo}" alt="" class="ringtpic" />
                                    <div class="ringtco">
                                        <p class="ringtct1">${item.name}</p>`
                        if (item.company_level != '') {
                            html += `<img src="${item.company_level}" class="userLevel" alt="${item.level_name}"/>`
                        }
                        html += `</div>
                                    <p class="ringtlr">${date}</p>
                                </a>
                                <p class="ringco">${item.content}</p>
                                <a href="javascript:;" class="ringco2">全文</a>
                                <div class="ringlilist">`
                        item.pictures.forEach(i => {
                            html += `<a href="javascript:;"><img src="${i.thumb_url}" alt="${i.pic_name}" class="rilipic plusBanner" data-url="${i.pic_url}" /></a>`;
                        })

                        html += `</div><div class="browse">
                                    <p class="brot">${item.read_count}人浏览</p>
                                    <div class="brolr">
                                        <a href="javascript:;" class="brolrlink ${item.has_dig == 1 ? "on" : ""}" deta-num="1" >
                                            <span class="brolrpic brolrpic2"></span><span class="num">${item.digg_count}</span>
                                        </a>
                                    </div>
                                </div>`
                        if (item.comments == "") {
                            html += '';
                        } else {
                            html += `<div class="brocomment">
                                <img src="img/brotop.png" alt="" class="brotop" /><div class="commentLists">`;
                            item.comments.forEach(p => {
                                html += `
                            <p class="brocoti"><a href="javascript:;" class="brocotlink">${p.nick_name}:</a>${p.content}</p>
                                    `;
                            })
                            html += `</div>`;
                            if (item.comments.length >= 5) {
                                html += `<a href="javascript:;" class="moreBtn" data-id="${item.id}">更多...</a>`;
                            }
                        }

                        html += `</div>
                            </div>`;
                    });
                    if (data.length < page_size) {
                        $('.notMore').css('display', 'flex');
                    }
                    $('#ringlist').append(html);
                } else if (res.status == 2) {
                    location.href = "fox://logout";
                } else {
                    alert(res.message);
                }
            }
        })
    }

    // 分享下载链接及备案信息底部
    if ($('.downLoad').length) {
        $.ajax({
            type: "post",
            url: url,
            data: { "method": "Api|share_bottom" },
            dataType: 'json',
            success: function(res) {
                if (res.status == 1) {
                    let data = res.data;
                    let html = '';
                    data.download.forEach(item => {
                        html += `
                <li><a href="${item.url}">${item.type_name}</a></li>
                `;
                    })
                    $('.dlLists').html(html);
                    $('.icp_info').html(data.icp_info);
                    $('.other_msg').html(data.other_msg);
                }
            }
        })
    }

    // 下拉加载更多
    $(window).scroll(function() {
        if ($(document).scrollTop() >= $(document).height() - $(window).height() - 1) {
            // console.log('我到底了');
            if ($('.notMore').css('display') != "flex") {
                page++;
                ajaxList(page);
            }
        }
    })
})